package distribuidos.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import distribuidos.modelo.*;


/**
 * Servlet implementation class LogoutServlet
 */
@WebServlet("/LogoutServlet")
public class MenuServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MenuServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
        String tipo=request.getParameter("tipo");
        RequestDispatcher rd;
        Sala per= (Sala) session.getAttribute("perp");
        String mod=request.getParameter("mod");
        
 /*   	if(per.getNombres()==null){
			System.out.println("persona "+ per.getNombres()+" "+tipo);
			 if(tipo.equals("A")) {
	        	 request.setAttribute("tipo", "A");
	        	 rd = request.getRequestDispatcher("IngresoPersonaA.jsp");
				 rd.forward(request, response);
	         }else if(tipo.equals("P")){
	        	 request.setAttribute("tipo", "A");
	        	 rd = request.getRequestDispatcher("IngresoPersonaP.jsp");
				 rd.forward(request, response);
	         }
		 }else if (mod.equals("menu")){
			 if(tipo.equals("A")) {
	        	 request.setAttribute("tipo", "A");
	        	 rd = request.getRequestDispatcher("mastera.jsp");
				 rd.forward(request, response);
	         }else if(tipo.equals("P")){
	        	 request.setAttribute("tipo", "A");
	        	 rd = request.getRequestDispatcher("masterp.jsp");
				 rd.forward(request, response);
	         }
		 }else if(mod.equals("consulta")){
			 rd = request.getRequestDispatcher("consultas.jsp");
			 rd.forward(request, response);
		 }
        
		rd=request.getRequestDispatcher("loguin.jsp");
		rd.forward(request, response);
*/
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		HttpSession session = request.getSession();
		session.invalidate();//destruye la sesion
		
		RequestDispatcher rd = request.getRequestDispatcher("mastera.jsp");
		rd.forward(request, response);
	}

}
